<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="108px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="报备单号" prop="reportNum">
        <el-input
          v-model="queryParams.reportNum"
          placeholder="请输入报备单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="reportInfoList">
      <el-table-column label="项目名称" align="center" prop="projectName" width="300px;" v-element-table-tooltip/>
      <el-table-column label="所属管辖大队" align="center" prop="deptName"/>
      <el-table-column label="备案时间" align="center" prop="filingDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.filingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进场上报次数" align="center" prop="entryReportCount" >
        <template slot-scope="scope">
          <router-link :to="{path:'/project/entryReport',query:{reportInfoId:scope.row.reportInfoId}}" class="link-type">
            <span>{{ scope.row.entryReportCount }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="占道上报次数" align="center" prop="jeevesReportCount">
        <template slot-scope="scope">
          <router-link :to="{path:'/project/jeevesReport',query:{reportInfoId:scope.row.reportInfoId}}" class="link-type">
            <span>{{ scope.row.jeevesReportCount }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="撤场上报次数" align="center" prop="withdrawalReportCount">
        <template slot-scope="scope">
          <router-link :to="{path:'/project/withdrawalReport',query:{reportInfoId:scope.row.reportInfoId}}" class="link-type">
            <span>{{ scope.row.withdrawalReportCount }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="施工检查次数" align="center" prop="checkRecordCount">
        <template slot-scope="scope">
          <router-link :to="{path:'/projectCheck/checkRecord',query:{reportInfoId:scope.row.reportInfoId}}" class="link-type">
            <span>{{ scope.row.checkRecordCount }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="施工检查问题次数" align="center" prop="check_problem_count">
        <template slot-scope="scope">
          <router-link :to="{path:'/projectCheck/checkProblem',query:{reportInfoId:scope.row.reportInfoId}}" class="link-type">
            <span>{{ scope.row.checkProblemCount }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="漏检次数" align="center" prop="unCheckCount"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
  import { selectProjectProcessTotal } from "@/api/statistics/reportForms";
  import { deptUserTreeSelect } from "@/api/system/user";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    name: "reportInfo",
    components: { Treeselect },
    dicts: ['business_cons_direction_type', 'business_cons_type'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 报备信息表格数据
        reportInfoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //  是否显示审核弹出层
        completeOpen: false,
        //  是否显示详情弹出层
        viewOpen: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          reportNum: null,
          buildUnit: null,
          construnctionUnit: null,
          approvalNumber: null,
          expresswayStartSectionId: null,
          expresswayEndSectionId: null,
          constructionType: null,
          telePhone: null,
          construnctionStartTime: null,
          construnctionEndTime: null,
          planInTime: null,
          reportStatus: null,
          deptId: null,
          isArchived: null,
          reportInfoId: null,
        },
        // 表单参数
        form: {},

        // 审核表单参数
        taskForm: {
          reportInfoId: "",// 报备id
          apprStatus: "0",//审批状态
          apprComent: "", // 意见内容
        },

        //  施工组织方案
        organizationFileData:[],
        //  施工许可文件
        licenseFileData:[],
        //  交通组织方案文件
        trafficFileData:[],
        //  应急预案文件
        emergencyPlanFileData:[],
        //  安全培训材料文件
        safetyTrainingFileData:[],
        // 资质证明材料文件
        qualificationCertificationFileData:[],
        //  其他材料文件
        otherFileData:[],

        //  高速路段option
        expresswaySectionOption:[],
        //  组织部门
        deptOptions: undefined,
        //  部门人员
        userOptions: undefined,
        //  审批记录
        reportApprLogList:[],
        //  审批状态
        reportStatusOption:[{label:'草稿',value:0},{label:'待接收',value:1},{label:'通过',value:2},{label:'驳回',value:3}],

        //  施工状态
        constructionStatusOption:[
          {label: '未进场', value: 0, type:''},
          {label: '非占道施工', value: 1, type:'info'},
          {label: '占道施工', value: 2, type:'success'},
          {label: '撤场', value: 3, type:'danger'},
          {label: '结束', value: 4, type:'warning'}
        ],
      };
    },
    created() {
      this.getList();
      this.getDeptTree();
    },
    methods: {
      /** 查询报备信息列表 */
      getList() {
        this.loading = true;
        selectProjectProcessTotal(this.queryParams).then(response => {
          this.reportInfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.reportInfoId);
        //从缓存里面获取用户类型
        const  userType = this.$store.state.user.userType;
        //执法端
        if (userType == "00") {
          //控制审批按钮  只有状态等于 1
          this.single = !(selection.length===1 && selection[0].reportStatus === 1 && selection[0].reviewedBy === this.currentUserId);
        }else{
          //控制修改按钮  只有状态等于 0 或者 3
          this.single = !(selection.length===1 && (selection[0].reportStatus === 0 || selection[0].reportStatus === 3) && selection[0].createBy === this.currentUserId);
        }
        this.multiple = !selection.length
      },

      /** 导出按钮操作 */
      handleExport() {
        this.download('statistics/reportForms/exportProjectProcessTotal', {
          ...this.queryParams
        }, `projectProcess_${new Date().getTime()}.xlsx`)
      },

      /** 查询部门下拉树结构 */
      getDeptTree() {
        deptUserTreeSelect().then(response => {
          this.deptOptions = response.data;
        });
      },
    },

  };
</script>
